package com.example.navbardemo.utils;

import com.example.navbardemo.fraction.SystemPage;
import ohos.aafwk.ability.Ability;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.ability.fraction.Fraction;
import ohos.aafwk.ability.fraction.FractionAbility;
import ohos.aafwk.ability.fraction.FractionManager;

import java.util.Optional;

public  class  FractionUtil {

    /**
     * 获取Fraction管理器对象
     *
     * @param abilitySlice      abilitySlice对象
     * @return
     */
    public   FractionManager getFractionManager(AbilitySlice abilitySlice){
        Ability ability = abilitySlice.getAbility();
        if(ability instanceof FractionAbility){
            FractionAbility fractionAbility = (FractionAbility) ability;
            return fractionAbility.getFractionManager();
        }
        return null;
    }

    public  void fractionHide(AbilitySlice abilitySlice){

        getFractionManager(abilitySlice)
                .startFractionScheduler()
                .hide(new SystemPage())
                .submit();
    }
}
